home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261exe.zip / DRIVERS.DOC < prev    next >
Text File  |  1993-05-26  |  29KB  |  679 lines

  1.    Copyright (C) 1989, 1990, 1991, 1992, 1993 Aladdin Enterprises.
  2.      All rights reserved.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.
  19.  
  20. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  21.  
  22. This file, drivers.doc, describes the interface between Ghostscript and
  23. device drivers.
  24.  
  25. For an overview of Ghostscript and a list of the documentation files, see
  26. README.
  27.  
  28. ********
  29. ******** Adding a driver ********
  30. ********
  31.  
  32. To add a driver to Ghostscript, all you need to do is edit devs.mak in
  33. two places.  The first is the list of devices, in the section headed
  34.  
  35. # -------------------------------- Catalog ------------------------------- #
  36.  
  37. Pick a name for your device, say smurf, and add smurf to the list.
  38. (Device names must be 1 to 8 characters, consisting of only letters,
  39. digits, and underscores, of which the first character must be a letter.
  40. Case is significant: all current device names are lower case.)
  41. The second is the section headed
  42.  
  43. # ---------------------------- Device drivers ---------------------------- #
  44.  
  45. Suppose the files containing the smurf driver are called joe and fred.
  46. Then you should add the following lines:
  47.  
  48. # ------ The SMURF device ------ #
  49.  
  50. smurf_=joe.$(OBJ) fred.$(OBJ)
  51. smurf.dev: $(smurf_)
  52.     $(SHP)gssetdev smurf $(smurf_)
  53.  
  54. joe.$(OBJ): joe.c ...and whatever it depends on
  55.  
  56. fred.$(OBJ): fred.c ...and whatever it depends on
  57.  
  58. If the smurf driver also needs special libraries, e.g., a library named
  59. gorf, then the gssetdev line should look like
  60.     $(SHP)gssetdev smurf $(smurf_)
  61.     $(SHP)gsaddmod smurf -lib gorf
  62.  
  63. ********
  64. ******** Keeping things simple
  65. ********
  66.  
  67. If you want to add a simple device (specifically, a black-and-white
  68. printer), you probably don't need to read the rest of this document; just
  69. use the code in an existing driver as a guide.  The Epson and BubbleJet
  70. drivers (gdevepsn.c and gdevbj10.c) are good models for dot-matrix
  71. printers, which require presenting the data for many scan lines at once;
  72. the DeskJet/LaserJet drivers (gdevdjet.c) are good models for laser
  73. printers, which take a single scan line at a time but support data
  74. compression.  For color printers, the DeskJet 500 C driver (gdevcdj.c) is
  75. a good place to start.
  76.  
  77. On the other hand, if you're writing a driver for some more esoteric
  78. device, or want to do something like add new settable attributes (besides
  79. page size and resolution), you probably do need at least some of the
  80. information in the rest of this document.  It might be a good idea for you
  81. to read it in conjunction with one of the existing drivers.
  82.  
  83. ********
  84. ******** Driver structure ********
  85. ********
  86.  
  87. A device is represented by a structure divided into three parts:
  88.  
  89.     - procedures that are shared by all instances of each device;
  90.  
  91.     - parameters that are present in all devices but may be different
  92.       for each device or instance; and
  93.  
  94.     - device-specific parameters that may be different for each instance.
  95.  
  96. Normally, the procedure structure is defined and initialized at compile
  97. time.  A prototype of the parameter structure (including both generic and
  98. device-specific parameters) is defined and initialized at compile time,
  99. but is copied and filled in when an instance of the device is created.
  100.  
  101. The gx_device_common macro defines the common structure elements, with the
  102. intent that devices define and export a structure along the following
  103. lines:
  104.  
  105.     typedef struct smurf_device_s {
  106.         gx_device_common;
  107.         ... device-specific parameters ...
  108.     } smurf_device;
  109.     smurf_device gs_smurf_device = {
  110.         sizeof(smurf_device),        * params_size
  111.         { ... procedures ... },        * procs
  112.         ... generic parameter values ...
  113.         ... device-specific parameter values ...
  114.     };
  115.  
  116. The device structure instance *must* have the name gs_smurf_device, where
  117. smurf is the device name used in devs.mak.
  118.  
  119. All the device procedures are called with the device as the first
  120. argument.  Since each device type is actually a different structure type,
  121. the device procedures must be declared as taking a gx_device * as their
  122. first argument, and must cast it to smurf_device * internally.  For
  123. example, in the code for the "memory" device, the first argument to all
  124. routines is called dev, but the routines actually use md to reference
  125. elements of the full structure, by virtue of the definition
  126.  
  127.     #define md ((gx_device_memory *)dev)
  128.  
  129. (This is a cheap version of "object-oriented" programming: in C++, for
  130. example, the cast would be unnecessary, and in fact the procedure table
  131. would be constructed by the compiler.)
  132.  
  133. Structure definition
  134. --------------------
  135.  
  136. This essentially duplicates the structure definition in gxdevice.h.
  137.  
  138. typedef struct gx_device_s {
  139.     int params_size;        /* size of this structure */
  140.     gx_device_procs *procs;        /* pointer to procedure structure */
  141.     char *name;            /* the device name */
  142.     int width;            /* width in pixels */
  143.     int height;            /* height in pixels */
  144.     float x_pixels_per_inch;    /* x density */
  145.     float y_pixels_per_inch;    /* y density */
  146.     gs_rect margin_inches;        /* margins around imageable area, */
  147.                     /* in inches */
  148.     gx_device_color_info color_info;    /* color information */
  149.     int is_open;            /* true if device has been opened */
  150. } gx_device;
  151.  
  152. The name in the structure should be the same as the name in devs.mak.
  153.  
  154. gx_device_common is a macro consisting of just the element definitions.
  155.  
  156. For sophisticated developers only
  157. ---------------------------------
  158.  
  159. If for any reason you need to change the definition of the basic device
  160. structure, or add procedures, you must change the following places:
  161.  
  162.     - This document and NEWS (if you want to keep the
  163.         documentation up to date).
  164.     - The definition of gx_device_common and/or the procedures
  165.         in gxdevice.h.
  166.     - The null device in gsdevice.c.  (Note that this device does
  167.         not allow procedure defaulting.)
  168.     - The tracing "device" in gstdev.c.  (Ditto.)
  169.     - The command list "device" in gxclist.c.  (Ditto.)
  170.     - The clip list accumulation and clipping "devices" in gxcpath.c.
  171.         (Ditto.)
  172.     - The "memory" devices in gdevmem.h and gdevmem*.c.  (Ditto.)
  173.     - The generic printer device macros in gdevprn.h.
  174.     - The generic printer device code in gdevprn.c.
  175.     - All the real devices in the standard Ghostscript distribution,
  176.         as listed in devs.mak.  (Most of the printer devices are
  177.         created with the macros in gdevprn.h, so you may not have to
  178.         edit the source code for them.)
  179.     - Any other drivers you have that aren't part of the standard
  180.         Ghostscript distribution.
  181.  
  182. You may also have to change the code for gx_default_get_props and/or
  183. gx_default_put_props (in gsdevice.c).  Note that if all you are doing
  184. is adding optional procedures, you do NOT have to modify any device
  185. drivers other than the ones specifically listed above; Ghostscript
  186. will substitute the default procedures properly.
  187.  
  188. ********
  189. ******** Coding conventions ********
  190. ********
  191.  
  192. While most drivers (especially printer drivers) follow a very similar
  193. template, there is one important coding convention that is not obvious
  194. from reading the code for existing drivers: Driver procedures must not use
  195. malloc to allocate any storage that stays around after the procedure
  196. returns.  Instead, they must use gs_malloc and gs_free, which have
  197. slightly different calling conventions.  (The prototypes for these are in
  198. gs.h, which is included in gx.h, which is included in gdevprn.h.)  This is
  199. necessary so that Ghostscript can clean up all allocated memory before
  200. exiting, which is essential in environments that provide only
  201. single-address-space multi-tasking (specifically, Microsoft Windows).
  202.  
  203. char *gs_malloc(uint num_elements, uint element_size,
  204.   const char *client_name);
  205.  
  206.     Like calloc, but unlike malloc, gs_malloc takes an element count
  207. and an element size.  For structures, num_elements is 1 and element_size
  208. is sizeof the structure; for byte arrays, num_elements is the number of
  209. bytes and element_size is 1.
  210.  
  211.     The client_name is used for tracing and debugging.  It must be a
  212. real string, not NULL.  Normally it is the name of the procedure in which
  213. the call occurs.
  214.  
  215. void gs_free(char *data, uint num_elements, uint element_size,
  216.   const char *client_name);
  217.  
  218.     Unlike free, gs_free demands that num_elements and element_size be
  219. supplied.  It also requires a client name, like gs_malloc.
  220.  
  221. ********
  222. ******** Types and coordinates ********
  223. ********
  224.  
  225. Coordinate system
  226. -----------------
  227.  
  228. Since each driver specifies the initial transformation from user to device
  229. coordinates, the driver can use any coordinate system it wants, as long as
  230. a device coordinate will fit in an int.  (This is only an issue on MS-DOS
  231. systems, where ints are only 16 bits.  User coordinates are represented as
  232. floats.)  Typically the coordinate system will have (0,0) in the upper
  233. left corner, with X increasing to the right and Y increasing toward the
  234. bottom.  This happens to be the coordinate system that all the currently
  235. supported devices use.  However, there is supposed to be nothing in the
  236. rest of Ghostscript that assumes this.
  237.  
  238. Drivers must check (and, if necessary, clip) the coordinate parameters
  239. given to them: they should not assume the coordinates will be in bounds.
  240. The fit_fill and fit_copy macros in gxdevice.h are very helpful in doing
  241. this.
  242.  
  243. Color definition
  244. ----------------
  245.  
  246. Ghostscript represents colors internally as RGB or CMYK values.  In
  247. communicating with devices, however, it assumes that each device has a
  248. palette of colors identified by integers (to be precise, elements of type
  249. gx_color_index).  Drivers may provide a uniformly spaced gray ramp or
  250. color cube for halftoning, or they may do their own color approximation,
  251. or both.
  252.  
  253. The color_info member of the device structure defines the color and
  254. gray-scale capabilities of the device.  Its type is defined as follows:
  255.  
  256. typedef struct gx_device_color_info_s {
  257.     int num_components;        /* 1 = gray only, 3 = RGB, */
  258.                     /* 4 = CMYK */
  259.     int depth;            /* # of bits per pixel */
  260.     gx_color_value max_gray;    /* # of distinct gray levels -1 */
  261.     gx_color_value max_rgb;        /* # of distinct color levels -1 */
  262.                     /* (only relevant if num_comp. > 1) */
  263.     gx_color_value dither_gray;    /* size of gray ramp for halftoning */
  264.     gx_color_value dither_rgb;    /* size of color cube ditto */
  265.                     /* (only relevant if num_comp. > 1) */
  266. } gx_device_color_info;
  267.  
  268. The following macros (in gxdevice.h) provide convenient shorthands for
  269. initializing this structure for ordinary black-and-white or color devices:
  270.  
  271. #define dci_black_and_white { 1, 1, 1, 0, 2, 0 }
  272. #define dci_color(depth,maxv,dither) { 3, depth, maxv, maxv, dither, dither }
  273.  
  274. The idea is that a device has a certain number of gray levels (max_gray
  275. +1) and a certain number of colors (max_rgb +1) that it can produce
  276. directly.  When Ghostscript wants to render a given RGB color as a device
  277. color, it first tests whether the color is a gray level.  (If
  278. num_components is 1, it converts all colors to gray levels.)  If so:
  279.  
  280.     - If max_gray is large (>= 31), Ghostscript asks the device to
  281. approximate the gray level directly.  If the device returns a
  282. gx_color_value, Ghostscript uses it.  Otherwise, Ghostscript assumes that
  283. the device can represent dither_gray distinct gray levels, equally spaced
  284. along the diagonal of the color cube, and uses the two nearest ones to the
  285. desired color for halftoning.
  286.  
  287. If the color is not a gray level:
  288.  
  289.     - If max_rgb is large (>= 31), Ghostscript asks the device to
  290. approximate the color directly.  If the device returns a
  291. gx_color_value, Ghostscript uses it.  Otherwise, Ghostscript assumes
  292. that the device can represent dither_rgb * dither_rgb * dither_rgb
  293. distinct colors, equally spaced throughout the color cube, and uses
  294. two of the nearest ones to the desired color for halftoning.
  295.  
  296. Types
  297. -----
  298.  
  299. Here is a brief explanation of the various types that appear as parameters
  300. or results of the drivers.
  301.  
  302. gx_color_value (defined in gxdevice.h)
  303.  
  304.     This is the type used to represent RGB color values.  It is
  305. currently equivalent to unsigned short.  However, Ghostscript may use less
  306. than the full range of the type to represent color values:
  307. gx_color_value_bits is the number of bits actually used, and
  308. gx_max_color_value is the maximum value (equal to
  309. 2^gx_max_color_value_bits - 1).
  310.  
  311. gx_device (defined in gxdevice.h)
  312.  
  313.     This is the device structure, as explained above.
  314.  
  315. gs_matrix (defined in gsmatrix.h)
  316.  
  317.     This is a 2-D homogenous coordinate transformation matrix, used by
  318. many Ghostscript operators.
  319.  
  320. gx_color_index (defined in gxdevice.h)
  321.  
  322.     This is meant to be whatever the driver uses to represent a device
  323. color.  For example, it might be an index in a color map.  Ghostscript
  324. doesn't ever do any computations with these values: it gets them from
  325. map_rgb_color or map_cmyk_color and hands them back as arguments to
  326. several other procedures.  The special value gx_no_color_index (defined as
  327. (gx_color_index)(-1)) means "transparent" for some of the procedures.  The
  328. type definition is simply:
  329.  
  330.     typedef unsigned long gx_color_index;
  331.  
  332. gs_prop_item (defined in gsprops.h)
  333.  
  334.     This is an element of a property list, which is used to read and
  335. set attributes in a device.  See the comments in gsprops.h, and the
  336. description of the get_props and put_props procedures below, for more
  337. detail.
  338.  
  339. gx_bitmap (defined in gxbitmap.h)
  340.  
  341.     This structure type represents a bitmap to be used as a tile for
  342. filling a region (rectangle).  Here is a copy of the relevant part of the
  343. file:
  344.  
  345. /*
  346.  * Structure for describing stored bitmaps.
  347.  * Bitmaps are stored bit-big-endian (i.e., the 2^7 bit of the first
  348.  * byte corresponds to x=0), as a sequence of bytes (i.e., you can't
  349.  * do word-oriented operations on them if you're on a little-endian
  350.  * platform like the Intel 80x86 or VAX).  Each scan line must start on
  351.  * a (32-bit) word boundary, and hence is padded to a word boundary,
  352.  * although this should rarely be of concern, since the raster and width
  353.  * are specified individually.  The first scan line corresponds to y=0
  354.  * in whatever coordinate system is relevant.
  355.  *
  356.  * For bitmaps used as halftone tiles, we may replicate the tile in
  357.  * X and/or Y, but it is still valuable to know the true tile dimensions.
  358.  */
  359. typedef struct gx_bitmap_s {
  360.     byte *data;
  361.     int raster;            /* bytes per scan line */
  362.     gs_int_point size;        /* width, height */
  363.     gx_bitmap_id id;
  364.     ushort rep_width, rep_height;    /* true size of tile */
  365. } gx_bitmap;
  366.  
  367. ********
  368. ******** Driver procedures ********
  369. ********
  370.  
  371. All the procedures that return int results return 0 on success, or an
  372. appropriate negative error code in the case of error conditions.  The
  373. error codes are defined in gserrors.h.  The relevant ones for drivers
  374. are as follows:
  375.  
  376.     gs_error_invalidfileaccess
  377.         An attempt to open a file failed.
  378.  
  379.     gs_error_limitcheck
  380.         An otherwise valid parameter value was too large for
  381.         the implementation.
  382.  
  383.     gs_error_rangecheck
  384.         A parameter was outside the valid range.
  385.  
  386.     gs_error_VMerror
  387.         An attempt to allocate memory failed.  (If this
  388.         happens, the procedure should release all memory it
  389.         allocated before it returns.)
  390.  
  391. If a driver does return an error, it should use the return_error
  392. macro rather than a simple return statement, e.g.,
  393.  
  394.     return_error(gs_error_VMerror);
  395.  
  396. This macro is defined in gx.h, which is automatically included by
  397. gdevprn.h but not by gserrors.h.
  398.  
  399. Most of the procedures that a driver may implement are optional.  If a
  400. device doesn't supply an optional procedure <proc>, the entry in the
  401. procedure structure may be either gx_default_<proc>, e.g.
  402. gx_default_tile_rectangle, or NULL or 0.  (The device procedure must also
  403. call the gx_default_ procedure if it doesn't implement the function for
  404. particular values of the arguments.)  Since C compilers supply 0 as the
  405. value for omitted structure elements, this convention means that
  406. statically initialized procedure structures will continue to work even if
  407. new (optional) members are added.
  408.  
  409. Life cycle
  410. ----------
  411.  
  412. Ghostscript "opens" and "closes" drivers explicitly; a driver can assume
  413. that no output operations will be done through it while it is closed.
  414. Ghostscript keeps track of whether a given driver is open, so a driver
  415. will never be opened when it is already open, or closed when it is already
  416. closed.
  417.  
  418. The following are the only driver procedures that may be called when the
  419. driver is closed:
  420.     open_device
  421.     get_initial_matrix
  422.     get_props
  423.     put_props
  424.  
  425. Open/close/sync
  426. ---------------
  427.  
  428. int (*open_device)(P1(gx_device *)) [OPTIONAL]
  429.  
  430.     Open the device: do any initialization associated with making the
  431. device instance valid.  This must be done before any output to the device.
  432. The default implementation does nothing.
  433.  
  434. void (*get_initial_matrix)(P2(gx_device *, gs_matrix *)) [OPTIONAL]
  435.  
  436.     Construct the initial transformation matrix mapping user
  437. coordinates (nominally 1/72" per unit) to device coordinates.  The default
  438. procedure computes this from width, height, and x/y_pixels_per_inch on the
  439. assumption that the origin is in the upper left corner, i.e.
  440.         xx = x_pixels_per_inch/72, xy = 0,
  441.         yx = 0, yy = -y_pixels_per_inch/72,
  442.         tx = 0, ty = height.
  443.  
  444. int (*sync_output)(P1(gx_device *)) [OPTIONAL]
  445.  
  446.     Synchronize the device.  If any output to the device has been
  447. buffered, send / write it now.  Note that this may be called several times
  448. in the process of constructing a page, so printer drivers should NOT
  449. implement this by printing the page.  The default implementation does
  450. nothing.
  451.  
  452. int (*output_page)(P3(gx_device *, int num_copies, int flush)) [OPTIONAL]
  453.  
  454.     Output a fully composed page to the device.  The num_copies
  455. argument is the number of copies that should be produced for a hardcopy
  456. device.  (This may be ignored if the driver has some other way to specify
  457. the number of copies.)  The flush argument is true for showpage, false for
  458. copypage.  The default definition just calls sync_output.  Printer drivers
  459. should implement this by printing and ejecting the page.
  460.  
  461. int (*close_device)(P1(gx_device *)) [OPTIONAL]
  462.  
  463.     Close the device: release any associated resources.  After this,
  464. output to the device is no longer allowed.  The default implementation
  465. does nothing.
  466.  
  467. Color mapping
  468. -------------
  469.  
  470. A given driver normally will implement either map_rgb_color or
  471. map_cmyk_color, but not both; black-and-white drivers do not need to
  472. implement either one.
  473.  
  474. gx_color_index (*map_rgb_color)(P4(gx_device *, gx_color_value red,
  475.   gx_color_value green, gx_color_value blue)) [OPTIONAL]
  476.  
  477.     Map a RGB color to a device color.  The range of legal values of
  478. the RGB arguments is 0 to gx_max_color_value.  The default algorithm uses
  479. the map_cmyk_color procedure if the driver supplies one, otherwise returns
  480. 1 if any of the values exceeds gx_max_color_value/2, 0 otherwise.
  481.  
  482.     Ghostscript assumes that for devices that have color capability
  483. (i.e., color_info.num_components > 1), map_rgb_color returns a color index
  484. for a gray level (as opposed to a non-gray color) iff red = green = blue.
  485.  
  486. gx_color_index (*map_cmyk_color)(P5(gx_device *, gx_color_value cyan,
  487.   gx_color_value magenta, gx_color_value yellow, gx_color_value black))
  488.   [OPTIONAL]
  489.  
  490.     Map a CMYK color to a device color.  The range of legal values of
  491. the CMYK arguments is 0 to gx_max_color_value.  The default algorithm
  492. calls the map_rgb_color procedure, with suitably transformed arguments.
  493.  
  494.     Ghostscript assumes that for devices that have color capability
  495. (i.e., color_info.num_components > 1), map_cmyk_color returns a color
  496. index for a gray level (as opposed to a non-gray color) iff cyan = magenta
  497. = yellow.
  498.  
  499. int (*map_color_rgb)(P3(gx_device *, gx_color_index color,
  500.   gx_color_value rgb[3])) [OPTIONAL]
  501.  
  502.     Map a device color code to RGB values.  The default algorithm
  503. returns (0 if color==0 else gx_max_color_value) for all three components.
  504.  
  505. Drawing
  506. -------
  507.  
  508. All drawing operations use device coordinates and device color values.
  509.  
  510. int (*fill_rectangle)(P6(gx_device *, int x, int y,
  511.   int width, int height, gx_color_index color))
  512.  
  513.     Fill a rectangle with a color.  The set of pixels filled is
  514. {(px,py) | x <= px < x + width and y <= py < y + height}.  In other words,
  515. the point (x,y) is included in the rectangle, as are (x+w-1,y), (x,y+h-1),
  516. and (x+w-1,y+h-1), but *not* (x+w,y), (x,y+h), or (x+w,y+h).  If width <=
  517. 0 or height <= 0, fill_rectangle should return 0 without drawing anything.
  518.  
  519. int (*draw_line)(P6(gx_device *, int x0, int y0, int x1, int y1,
  520.   gx_color_index color)) [OPTIONAL]
  521.  
  522.     Draw a minimum-thickness line from (x0,y0) to (x1,y1).  The
  523. precise set of points to be filled is defined as follows.  First, if y1 <
  524. y0, swap (x0,y0) and (x1,y1).  Then the line includes the point (x0,y0)
  525. but not the point (x1,y1).  If x0=x1 and y0=y1, draw_line should return 0
  526. without drawing anything.
  527.  
  528. Bitmap imaging
  529. --------------
  530.  
  531. Bitmap (or pixmap) images are stored in memory in a nearly standard way.
  532. The first byte corresponds to (0,0) in the image coordinate system: bits
  533. (or polybit color values) are packed into it left-to-right.  There may be
  534. padding at the end of each scan line: the distance from one scan line to
  535. the next is always passed as an explicit argument.
  536.  
  537. int (*copy_mono)(P11(gx_device *, const unsigned char *data, int data_x,
  538.   int raster, gx_bitmap_id id, int x, int y, int width, int height,
  539.   gx_color_index color0, gx_color_index color1))
  540.  
  541.     Copy a monochrome image (similar to the PostScript image
  542. operator).  Each scan line is raster bytes wide.  Copying begins at
  543. (data_x,0) and transfers a rectangle of the given width at height to the
  544. device at device coordinate (x,y).  (If the transfer should start at some
  545. non-zero y value in the data, the caller can adjust the data address by
  546. the appropriate multiple of the raster.)  The copying operation writes
  547. device color color0 at each 0-bit, and color1 at each 1-bit: if color0 or
  548. color1 is gx_no_color_index, the device pixel is unaffected if the image
  549. bit is 0 or 1 respectively.  If id is different from gx_no_bitmap_id, it
  550. identifies the bitmap contents unambiguously; a call with the same id will
  551. always have the same data, raster, and data contents.
  552.  
  553.     This operation is the workhorse for text display in Ghostscript,
  554. so implementing it efficiently is very important.
  555.  
  556. int (*tile_rectangle)(P10(gx_device *, const gx_bitmap *tile,
  557.   int x, int y, int width, int height,
  558.   gx_color_index color0, gx_color_index color1,
  559.   int phase_x, int phase_y)) [OPTIONAL]
  560.  
  561.     Tile a rectangle.  Tiling consists of doing multiple copy_mono
  562. operations to fill the rectangle with copies of the tile.  The tiles are
  563. aligned with the device coordinate system, to avoid "seams".
  564. Specifically, the (phase_x, phase_y) point of the tile is aligned with the
  565. origin of the device coordinate system.  (Note that this is backwards from
  566. the PostScript definition of halftone phase.)  phase_x and phase_y are
  567. guaranteed to be in the range [0..tile->width) and [0..tile->height)
  568. respectively.
  569.  
  570.     If color0 and color1 are both gx_no_color_index, then the tile is
  571. a color pixmap, not a bitmap: see the next section.
  572.  
  573. Pixmap imaging
  574. --------------
  575.  
  576. Pixmaps are just like bitmaps, except that each pixel occupies more than
  577. one bit.  All the bits for each pixel are grouped together (this is
  578. sometimes called "chunky" or "Z" format).  The number of bits per pixel is
  579. given by the color_info.depth parameter in the device structure: the legal
  580. values are 1, 2, 4, 8, 16, 24, or 32.  The pixel values are device color
  581. codes (i.e., whatever it is that map_rgb_color returns).
  582.  
  583. int (*copy_color)(P9(gx_device *, const unsigned char *data, int data_x,
  584.   int raster, gx_bitmap_id id, int x, int y, int width, int height))
  585.  
  586.     Copy a color image with multiple bits per pixel.  The raster is in
  587. bytes, but x and width are in pixels, not bits.  If the device doesn't
  588. actually support color, this is OPTIONAL; the default is equivalent to
  589. copy_mono with color0 = 0 and color1 = 1.  If id is different from
  590. gx_no_bitmap_id, it identifies the bitmap contents unambiguously; a call
  591. with the same id will always have the same data, raster, and data
  592. contents.
  593.  
  594. tile_rectangle can also take colored tiles.  This is indicated by the
  595. color0 and color1 arguments both being gx_no_color_index.  In this case,
  596. as for copy_color, the raster and height in the "bitmap" are interpreted
  597. as for real bitmaps, but the x and width are in pixels, not bits.
  598.  
  599. Reading bits back
  600. -----------------
  601.  
  602. int (*get_bits)(P4(gx_device *, int y, byte *str, byte **actual_data))
  603.   [OPTIONAL]
  604.  
  605.     Read one scan line of bits back from the device into the area
  606. starting at str, starting with scan line y.  If the bits cannot be
  607. read back (e.g., from a printer), return -1; otherwise return a value
  608. as described below.  The contents of the bits beyond the last valid
  609. bit in the scan line (as defined by the device width) are
  610. unpredictable.
  611.  
  612.     If actual_data is NULL, the bits are always returned at str.
  613. If actual_data is not NULL, get_bits may either copy the bits to str
  614. and set *actual_data = str, or it may leave the bits where they are
  615. and return a point to them in *actual_data.  In the latter case, the
  616. bits are guaranteed to start on a 32-bit boundary and to be padded to
  617. a multiple of 32 bits; also in this case, the bits are not guaranteed
  618. to still be there after the next call on get_bits.
  619.  
  620. Properties
  621. ----------
  622.  
  623. Devices may have an open-ended set of properties, which are simply pairs
  624. consisting of a name and a value.  The value may be of various types:
  625. integer, boolean, float, string, array of integer, or array of float.
  626.  
  627. Property lists are somewhat complex.  If your device has properties beyond
  628. those of a straightforward display or printer, we strongly advise using
  629. the code for the default implementation of get_props and put_props in
  630. gsdevice.c as a model for your own code.
  631.  
  632. int (*get_props)(P2(gx_device *dev, gs_prop_item *plist)) [OPTIONAL]
  633.  
  634.     Read all the properties of the device into the property list at
  635. plist.  Return the number of properties.  See gsprops.h for more details,
  636. gx_default_get_props in gsdevice.c for an example.
  637.  
  638.     If plist is NULL, just return the number of properties plus the
  639. total number of elements in all array-valued properties.  This is how the
  640. getdeviceprops operator finds out how much storage to allocate for the
  641. property list.
  642.     
  643. int (*put_props)(P3(gx_device *dev, gs_prop_item *plist,
  644.   int count)) [OPTIONAL]
  645.  
  646.     Set the properties of the device from the property list at plist.
  647. Return 0 if everything was OK, an error code
  648. (gs_error_undefined/typecheck/rangecheck/limitcheck) if some property had
  649. an invalid type or out-of-range value.  See gsprops.h for more details,
  650. gx_default_put_props in gsdevice.c for an example.
  651.  
  652.     Changing device properties may require closing the device and
  653. reopening it.  If this is the case, the put_props procedure should just
  654. close the device; a higher-level routine (gs_putdeviceprops) will reopen
  655. it.
  656.  
  657. External fonts
  658. --------------
  659.  
  660. Drivers may include the ability to display text.  More precisely, they may
  661. supply a set of procedures that in turn implement some font and text
  662. handling capabilities.  These procedures are documented in another file,
  663. xfonts.doc.  The link between the two is the driver procedure that
  664. supplies the font/text procedures:
  665.  
  666. xfont_procs *(*get_xfont_procs)(P1(gx_device *dev)) [OPTIONAL]
  667.  
  668.     Return a structure of procedures for handling external fonts and
  669. text display.  A NULL value means that this driver doesn't provide this
  670. capability.
  671.  
  672. For technical reasons, a second procedure is also needed:
  673.  
  674. gx_device *(*get_xfont_device)(P1(gx_device *dev)) [OPTIONAL]
  675.  
  676.     Return the device that implements get_xfont_procs in a non-default
  677. way for this device, if any.  Except for certain special internal devices,
  678. this is always the device argument.
  679.